package sanrenxing.dayEnd.backRepertoryTotal.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Stocksector;
import sanrenxing.dayEnd.backRepertoryTotal.service.StocksectorBiz;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/stocrud")
public class StocksectorController {
    /*定义业务层接口*/
    @Autowired
    private StocksectorBiz stocksectorBiz;

    @GetMapping("/sto")
    public Map<String,Object>  queryAll(int page, int limit, Stocksector stocksector){
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count", stocksectorBiz.count(stocksector));
        map.put("data",stocksectorBiz.queryAll(stocksector,limit,(page-1)*limit));
        return map;
    }
    //添加数据
    @PostMapping("/sto")
    public String addFund(@RequestBody Stocksector stocksector) {
        int rows=stocksectorBiz.add(stocksector);
        return rows>0?"add success":"failure";
    }

    //删除数据
    @DeleteMapping("/sto/{str}")
    public String deleteFund(@PathVariable String str){
        //调用业务层删除数据
        int rows=stocksectorBiz.delete(str);
        return rows>0?"delete success":"delete failure";
    }
    //修改数据
    @PutMapping("/sto")
    public String updateFund(@RequestBody Stocksector stocksector){
        //调用业务层修改数据
        int rows=stocksectorBiz.update(stocksector);
        return rows>0?"update success":"update failure";
    }
}
